#coding=utf-8
'''
Created on 2013年9月4日

@author: xuben

跨服武斗
'''

from ..common import Command, SocketService
from ..common.SocketService import gameSocketService, kfSocketService
import KfwdData

'''
获取跨服武斗信息
'''
def getKfwdInfo():
    command = Command.GET_KFWD_INFO
    params = ''
    gameSocketService.send(command, params, getKfwdInfoCallback)

'''
获取跨服武斗信息回调
'''
def getKfwdInfoCallback(data):
    KfwdData.init(data)
    
'''
登录跨服武斗
'''
def kfwdLogin():
    if SocketService.kfSocketService == None:
        SocketService.kfSocketService = SocketService.SocketService()
        ip = SocketService.getIp(KfwdData.matchAdress)
        print u'ip地址：', ip
        addr = (ip, int(KfwdData.matchPort))
        SocketService.kfSocketService.connect(addr)
    command = Command.KFWD_LOGIN
    params = 'competitorId=' + str(KfwdData.completedId)\
     + '&certificate=' + KfwdData.certifacate
    kfSocketService.send(command, params, kfwdLoginCallback)
    
'''
登录跨服武斗回调
'''
def kfwdLoginCallback(data):
    print u'跨服武斗登录成功'
    print data